﻿using System.ComponentModel;
using System.Reflection;

namespace DDD.Common.Extensions;

public static class AttributeExtension
{
    /// <summary>
    /// 获取属性上面的Description
    /// </summary>
    /// <param name="property"></param>
    /// <returns></returns>
    public static string GetDescription(this PropertyInfo? property)
    {
        if (property == null) return string.Empty;

        var attribute = Attribute.GetCustomAttribute(property, typeof(DescriptionAttribute));
        if (attribute != null)
            return ((DescriptionAttribute)attribute)?.Description ?? string.Empty;

        return string.Empty;
    }
}
